import router from '../router'
import axios from 'axios'

// axios请求配置
var root = process.env.VUE_APP_BASE_API
axios.interceptors.request.use(config => {
  // --请求之前重新拼装url--
  config.url = root + config.url
  return config
})

router.beforeEach((to, from, next) => {
  if (to.meta.requireAuth) {
    if (sessionStorage.token) {
      next()
    } else {
      alert('请先登录！')
      next({
        path: '/'
      })
    }
  } else {
    next()
  }
})

export default axios